package view.panels;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;

import utilities.EPatterns;
import utilities.PatternsInfoLoader;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/

public class StateAndStrategyPanel extends javax.swing.JPanel {
	
	/**
	 * CONSTANTES
	 */
	private static final String CLASS_DIAGRAM_TITLE = "Structure";
	
	/**
	 * 
	 */
	private EPatterns pattern = EPatterns.State;
	
	/**
	 * GUI
	 */
	private static final long serialVersionUID = 1L;
	private BufferedImage patternImage;
	private JLabel classDiagramTitleLabel;
	private JEditorPane patternInfoText;
	private JScrollPane scrollPane;
	
	
	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new StateAndStrategyPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public StateAndStrategyPanel() {
		super();
		initGUI();
	}
	
	public StateAndStrategyPanel(EPatterns pattern) {
		super();
		this.pattern = pattern;
		initGUI();
	}
	
	private void initGUI() {
		try {
			GridBagLayout thisLayout = new GridBagLayout();
			this.setBackground(Color.white);
			thisLayout.rowWeights = new double[] {0.001, 0.1};
			thisLayout.rowHeights = new int[] {1, 7};
			thisLayout.columnWeights = new double[] {0.1, 0.1};
			thisLayout.columnWidths = new int[] {7, 7};
			this.setLayout(thisLayout);
			this.setBackground(new java.awt.Color(255,255,255));
			this.setPreferredSize(new Dimension(1100, 515));
			this.setMaximumSize(new Dimension(1100, 515));
			this.setMinimumSize(new Dimension(1100, 515));

			{
				classDiagramTitleLabel = new JLabel();
				classDiagramTitleLabel.setText(CLASS_DIAGRAM_TITLE);
				classDiagramTitleLabel.setFont(new java.awt.Font("Curier New",Font.BOLD,18));
				this.add(classDiagramTitleLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(30, 40, 0, 0), 0, 0));
			}
			{
				patternImage = ImageIO.read(new File(System.getProperty("user.dir") + PatternsInfoLoader.getPatternProperty(pattern, PatternsInfoLoader.PATTERN_IMAGE_PATH))); 
				JLabel picLabel = new JLabel(new ImageIcon(patternImage));
				picLabel.setPreferredSize(new Dimension(650, 450));
				picLabel.setMaximumSize(new Dimension(650, 450));
				picLabel.setMinimumSize(new Dimension(650, 450));
				this.add(picLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
				
			}
			{
				patternInfoText = new JEditorPane(new HTMLEditorKit().getContentType(),"");
				patternInfoText.setEditable(false);
				patternInfoText.setContentType("text/html");  
				patternInfoText.setText((String) PatternsInfoLoader.getPatternProperty(pattern, PatternsInfoLoader.PATTERN_DESCRIPTION));
				patternInfoText.setBackground(Color.white);
				patternInfoText.setBorder(BorderFactory.createCompoundBorder(null,null));
				Font font = new Font("Segoe UI", Font.PLAIN, 24);
			    String bodyRule = "body { font-family: " + font.getFamily() + "; }";
			    ((HTMLDocument)patternInfoText.getDocument()).getStyleSheet().addRule(bodyRule);
				patternInfoText.setFont(new java.awt.Font("Curier New",0,12));
				scrollPane = new JScrollPane(patternInfoText);
				scrollPane.setPreferredSize(new java.awt.Dimension(420, 515));
				scrollPane.setMaximumSize(new java.awt.Dimension(420, 515));
				scrollPane.setMinimumSize(new java.awt.Dimension(420, 515));
				scrollPane.setFont(new java.awt.Font("Curier New",0,12));
				this.add(scrollPane, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(-60, 0, 0, 0), 0, 0));
				scrollPane.setBorder(new LineBorder(new java.awt.Color(255,255,255), 1, false));
				patternInfoText.setCaretPosition(0);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
